$fn = 80;

swsize = 25.4 * 0.75;	// switch size

case_width = 150;
case_length = 180;

top_thick = 11;
top_cutout_offset = 15;

bottom_thick = 8;
bottom_cutout_width = swsize * 5 + 10;
bottom_cutout_length = swsize * 4.75 + 20;

pcb_width = 99;
pcb_length = 99;
pcb_thick = 1.6;
pcb_miter = 3;

module top_board()
{
	top_cutout_width = swsize * 5;
	top_cutout_length = swsize * 4.75;
	key_space = 0.7;
	
	difference()
	{
		cube([case_width, case_length, top_thick]);
		translate([(case_width - top_cutout_width)/2, top_cutout_length - top_cutout_offset, -1])
			linear_extrude(height = top_thick + 2)
				polygon(points=[[-key_space,-key_space], [-key_space, swsize*4 + key_space],
							[swsize-key_space, swsize*4+key_space], [swsize-key_space, swsize*4.5+key_space],
							[swsize*2-key_space, swsize*4.5+key_space], [swsize*2-key_space, swsize*4.75+key_space],
							[swsize*3+key_space, swsize*4.75+key_space], [swsize*3+key_space, swsize*4.5+key_space],
							[swsize*4+key_space, swsize*4.5+key_space], [swsize*4+key_space, swsize*4+key_space],
							[swsize*5+key_space, swsize*4+key_space], [swsize*5+key_space, -key_space],
							[swsize*4-key_space, -key_space], [swsize*4-key_space, swsize*0.5-key_space],
							[swsize*3-key_space, swsize*0.5-key_space], [swsize*3-key_space, swsize*0.75-key_space],
							[swsize*2+key_space, swsize*0.75-key_space], [swsize*2+key_space, swsize*0.5-key_space],
							[swsize*1+key_space, swsize*0.5-key_space], [swsize*1+key_space, -key_space],
							[-key_space, -key_space]]);

	}
}

module bottom_board()
{
	translate([0,0,-bottom_thick])
	difference()
	{
		cube([case_width, case_length, bottom_thick]);
		translate([(case_width - bottom_cutout_width) / 2, case_length - bottom_cutout_length + 1, -0.5])
			cube([bottom_cutout_width, bottom_cutout_length + 1, bottom_thick+1]);
	}
}

module pcb()
{
	# translate([(case_width - pcb_width) / 2, case_length - pcb_length - 8, -pcb_thick])
	difference()
	{
		translate([pcb_miter, pcb_miter, 0])
			minkowski()
			{
				cube([pcb_width - pcb_miter*2, pcb_length - pcb_miter*2, pcb_thick/2]);
				cylinder(r = pcb_miter, h = pcb_thick/2);
			}
		//cube([pcb_width, pcb_length, pcb_thick]);

		// these are created with drl2pcb.pl
		//include <pcb_drills.scad>

		// only the mounting holes
		translate([3.683, 82.5535, -0.5]) cylinder(r = 1.2446, h = pcb_thick+1);
		translate([25.908, 4.4485, -0.5]) cylinder(r = 1.2446, h = pcb_thick+1);
		translate([72.898, 4.4485, -0.5]) cylinder(r = 1.2446, h = pcb_thick+1);
		translate([95.123, 82.5535, -0.5]) cylinder(r = 1.2446, h = pcb_thick+1);
	}
}

module edges()
{
	translate([-.5,0, 5]) rotate([6, 0, 0]) 
		cube([case_width+1, case_length, top_thick]);

	translate([0,-0.5, 5]) rotate([0, -45, 0]) 
		cube([10, case_length+1, 10]);
		
	translate([case_width,-0.5, 5]) rotate([0, -45, 0]) 
		cube([10, case_length+1, 10]);
}

module battery()
{
	battx = 58;
	batty = 42;
	battz = 13.5;
	
	translate([(case_width - battx)/2, (case_length - bottom_cutout_length) - batty + 1, -bottom_thick])
		cube([battx, batty, battz]);
}

//projection(cut = true) translate([0,0,1])
translate([-case_width/2, -case_length/2, 0])
{
	difference()
	{
		union()
		{
			top_board();
			bottom_board();
			//pcb();
		}
		edges();
		battery();
	}
}
